<?php
namespace app\admin\model;

use think\Model;

class Member extends Model
{
    protected $readonly = ['mobile'];
    
    protected $insert  = ['create_time'];
    
	//protected $update = [];
	
    protected function setPasswordAttr($value)
    {
        return md5($value);
    }
    public function getCreatetimeTurnAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['create_time']);
    }
    
    public function findInfo($where,$field = '*') {
        $res = $this->where($where)->field($field)->find();
        return empty($res)?array():$res->toArray();
    }
    
        /*
         * 会员手续费明细
         * @param mixed $where 查询条件
         * @param mixed $startTime 开始时间
         * @param mixed endTime 结束时间
         * @param mixed $page 分页
         * @author cpy(1442435897@qq.com)
         * @return array
         */
        public function memberFeeDetails($where,$startTime,$endTime,$sort = 'date desc',$field1 = '*',$field2 = '*') {
            $recharge = $this->alias('a')->join('tf_recharge b','b.user_id = a.id','LEFT')->where($where)->field($field1)->buildSql();
            $getcash = $this->alias('a')->join('tf_getcash c','c.user_id = a.id','LEFT')->where($where)->field($field2)->union([$recharge])->buildSql();
            return $this->table($getcash . ' a')->where('status',2)->whereTime('date','between',[$startTime,$endTime])->order($sort)->paginate('', false, page_param());
        }
        
        /*
         * 会员充值手续费明细
         * @param mixed $where 查询条件
         * @param mixed $startTime 开始时间
         * @param mixed endTime 结束时间
         * @param mixed $page 分页
         * @author cpy(1442435897@qq.com)
         * @return array
         */
        public function memberRechargeFeeDetails($where,$startTime,$endTime,$sort = 'b.id desc',$field = '*') {
            return $this->alias('a')->join('tf_recharge b','b.user_id = a.id','LEFT')->where($where)->field($field)
                    ->whereTime('b.date','between',[$startTime,$endTime])->order($sort)->paginate('', false, page_param());
        }
        
        /*
         * 会员提现手续费明细
         * @param mixed $where 查询条件
         * @param mixed $startTime 开始时间
         * @param mixed endTime 结束时间
         * @param mixed $page 分页
         * @author cpy(1442435897@qq.com)
         * @return array
         */
        public function memberGetcashFeeDetails($where,$startTime,$endTime,$sort = 'c.id desc',$field = '*') {
            return $this->alias('a')->join('tf_getcash c','c.user_id = a.id','LEFT')->where($where)->field($field)
                    ->whereTime('c.date','between',[$startTime,$endTime])->order($sort)->paginate('', false, page_param());
        }
    
    
}